﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.ClearScript.V8;

namespace Script.ClearScript_V8
{
    /// <summary>
    /// 用于脚本间共享数据
    /// </summary>
    public class Data
    {
        private Dictionary<dynamic, dynamic> _data;

        public Data()
        {
            _data = new Dictionary<dynamic, dynamic>();

        }
        /// <summary>
        /// 根据键获取值,无此键则返回null
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public dynamic Get(dynamic key)
        {
            return _data.ContainsKey(key) ? _data[key] : null;
        }
        /// <summary>
        /// 设置键对应的值,已有则覆盖
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        public void Set(dynamic key, dynamic value)
        {
            _data[key] = value;
        }
        /// <summary>
        /// 如果已存在键则返回true,否则返回false
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public bool Has(dynamic key)
        {
            return _data.ContainsKey(key);
        }
        /// <summary>
        /// 删除键
        /// </summary>
        /// <param name="key"></param>
        public void Remove(dynamic key)
        {
            if (_data.ContainsKey(key))
                _data.Remove(key);
        }
    }
}
